package study.javaee.practice.entity;

import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

//spring security鉴权实体
@Getter
@Setter
public class UserDetailsEntity implements UserDetails {

    User user;
    static final Collection<? extends GrantedAuthority> AUTH_COMMON = Collections.singletonList(new SimpleGrantedAuthority("ROLE_COMMON"));
    static final Collection<? extends GrantedAuthority> AUTH_SUPER = Collections.singletonList(new SimpleGrantedAuthority("ROLE_SUPER"));
    static final Collection<? extends GrantedAuthority> AUTH_ADMIN = Collections.singletonList(new SimpleGrantedAuthority("ROLE_ADMIN"));

    public UserDetailsEntity(User user){
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        switch (user.getType()){
            case 1: return AUTH_COMMON;
            case 2: return AUTH_SUPER;
            case 3: return AUTH_ADMIN;
            default:return null;
        }
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
